﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using LGE;
using Microsoft.Xna.Framework;

namespace Thaneros
{
    class Punch : GameObject
    {
        public bool isActive = false;
        Vector2 posGap = new Vector2(67, 0);
        SpriteSheet ss;

        public Punch(PlayScreen ps)
            : base(ps, Engine.Load<Texture2D>("Images\\Thanatos\\attack_arm"))
        {
            ss = new SpriteSheet(this, 14, 40, false);
            hitBox.Width /= ss.nFrames;
        }

        public override void Update(GameTime gameTime)
        {
            if (!isActive) return;

            ss.Update(gameTime);
            position = ps.c.position + (ps.c.isFacingLeft ? -1 : 1) * posGap;
            foreach (Enemy e in ps.enemies) if (this.Collision(e)) e.alive = false;
            if (ss.completed)
            {
                ss.completed = false; 
                ss.actualFrame = 0;
                isActive = false;
                ps.c.state.Change(States.StandThanatos);
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (isActive)
            {
                if (ps.c == null || sprite == null) return;

                drawPosition = position - ps.c.position + ps.c.drawPosition;
                spriteBatch.Draw(sprite, drawPosition, sourceRectangle, Color.White, rotation, origin, scale, ps.c.isFacingLeft ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
            }
        }

    }
}
